package org.maylove.wuziqi.service;

import org.maylove.wuziqi.dao.NoticeDao;
import org.maylove.wuziqi.pojo.notice.Notice;
import org.maylove.wuziqi.pojo.notice.dto.GetNoticeDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class NoticeServiceImpl implements NoticeService {
    @Autowired
    NoticeDao noticeDao;
    @Override
    public List<Notice> getMainNotice() {
        return noticeDao.getMainNotice();
    }

    @Override
    public List<Notice> getAllNotice(GetNoticeDto getNoticeDto) {
        return noticeDao.getAllNotice(getNoticeDto.getPageNum()*(getNoticeDto.getPagePos()-1),getNoticeDto.getPageNum());
    }

    @Override
    public void addNotice(Notice notice) {
        notice.setNoticeId(java.time.Instant.now().toEpochMilli());
        notice.setUpdateTime(LocalDateTime.now());
        noticeDao.save(notice);
    }

    @Override
    public Long getUserId(Long noticeId) {
        return noticeDao.findByNoticeId(noticeId).getUserId();
    }

    @Override
    public void deleteNotice(Long noticeId) {
        noticeDao.deleteByNoticeId(noticeId);
    }
}
